package com.sskj.mine.ui.activity;


import android.os.Bundle;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.allen.library.SuperTextView;
import com.sskj.common.base.App;
import com.sskj.common.rxbus2.RxBus;
import com.sskj.common.util.ClickUtil;
import com.sskj.common.util.ToastUtil;
import com.sskj.lib.RConfig;
import com.sskj.lib.RxBusCode;
import com.sskj.lib.base.BaseActivity;
import com.sskj.lib.bean.AppVersionBean;
import com.sskj.lib.ui.fragment.AppUpDateFragment;
import com.sskj.lib.util.APKVersionCodeUtils;
import com.sskj.mine.R;
import com.sskj.mine.R2;
import com.sskj.mine.presenter.MineAboutActivityPresenter;

import butterknife.BindView;
import butterknife.ButterKnife;
import sskj.lee.appupdatelibrary.BaseUpdateDialogFragment;
import sskj.lee.appupdatelibrary.BaseVersion;

@Route(path = RConfig.MINE_ABOUT)
public class MineAboutActivity extends BaseActivity<MineAboutActivityPresenter> {
    @BindView(R2.id.tvTitle)
    TextView tvTitle;
    @BindView(R2.id.left_img)
    ImageView leftImg;
    @BindView(R2.id.left_tv)
    TextView leftTv;
    @BindView(R2.id.ivBack)
    LinearLayout ivBack;
    @BindView(R2.id.right_tv)
    TextView rightTv;
    @BindView(R2.id.ivRight)
    ImageView ivRight;
    @BindView(R2.id.mine_xieyi)
    SuperTextView mineXieyi;
    @BindView(R2.id.mine_version)
    SuperTextView mineVersion;
    @BindView(R2.id.version)
    TextView version;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_mine_about;
    }

    @Override
    public MineAboutActivityPresenter getPresenter() {
        return new MineAboutActivityPresenter();
    }

    @Override
    protected void initView() {
        super.initView();
        tvTitle.setText(App.INSTANCE.getString(R.string.mine_mineAboutActivity1_j));
        version.setText(App.INSTANCE.getString(R.string.mine_mineUsActivity2_j) + APKVersionCodeUtils.getVerName(this));
        ClickUtil.click(mineVersion, () -> {
            mPresenter.getNewVersion();
        });
        ClickUtil.click(mineXieyi, () -> {
            ARouter.getInstance().build(RConfig.MINE_PROTOCAL)
                    .navigation();
        });
    }

    public void onVersionDataSuccess(AppVersionBean versionBean) {
        if (versionBean == null) {
            return;
        }
        String verName = APKVersionCodeUtils.getVerName(this);
        versionBean.setViewStyle(BaseVersion.NOTIFYCATION_STYLE);
        if (APKVersionCodeUtils.compareVersion(versionBean.getVersion(), verName) == 1) {
            android.app.FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
            getFragmentManager().beginTransaction();
            AppUpDateFragment appUpDateFragment = new AppUpDateFragment();//自定义UI
            Bundle bundle = new Bundle();
            bundle.putSerializable(BaseUpdateDialogFragment.INTENT_KEY, versionBean);
            appUpDateFragment.setArguments(bundle);
            appUpDateFragment.show(fragmentTransaction, "update");
        }
    }

}
